package com.nisco.ampf.util;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class HttpThread extends Thread {
	private Handler handle = null;
	ProgressDialog progressDialog = null;
	String[] list;
	String stackNo = null;
	String plateNo = null;
	String methodName = null;
	WebServerConn serverConn = null;
	private int METHOD_NAME;

	// 构造函数
	public HttpThread(Handler hander) {
		handle = hander;

	}

	/**
	 * 启动线程
	 */
	public void doStart(Context context, String stackStr, String palteStr,
			String methodStr) {
		stackNo = stackStr;
		plateNo = palteStr;
		methodName = methodStr;
		//判断传入的是哪个方法
		if (methodStr == "queryStack") {
			METHOD_NAME = 1;
		}
		progressDialog = ProgressDialog.show(context, "提示", "正在查询数据...", true);
		this.start();
	}

	/**
	 * 线程运行
	 */
	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
		try {
			serverConn = new WebServerConn();
			//根据不同的方法调用不同的函数
			switch (METHOD_NAME) {
			case 1:
				list = serverConn.queryStack(stackNo, plateNo);
				break;
			default:
				break;
			}
			// 取消进度对话框
			progressDialog.dismiss();
			// 构造消息
			Message message = handle.obtainMessage();
			Bundle b = new Bundle();
			b.putStringArray("data", list);
			message.setData(b);
			handle.sendMessage(message);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {

		}
	}
}
